import regeneratorRuntime from '../../lib/wxPromise.min.js'
let WxParse = require('../../lib/wxParse/wxParse.js')
let util = require('../../utils/util.js')
import QRCode from '../../utils/weapp-qrcode.js'
import * as API_Goods from '../../api/goods'
import * as API_Members from '../../api/members'
import * as API_Trade from '../../api/trade'
import * as API_Promotions from '../../api/promotions'
import * as API_Common from '../../api/common.js'
import * as API_Distribution from '../../api/distribution.js'
import * as API_Shop from '../../api/shop.js'

import {
  Foundation
} from '../../ui-utils/index.js'

Page({
  data: {
    /** 商品信息相关 */
    goods_id: 0, //商品id
    goods: {}, //商品详情信息
    param_list: [], //商品参数
    gallery_list: [], //商品轮播图片
    /** 促销相关 */
    promotions: '', // 促销信息
    showPromotion: true,
    prom: '', //积分信息
    groupbuy: '', //团购信息
    seckill: '', //限时信息
    assemble: '', //拼团信息
    assembleOrderList: '', //待成团订单
    is_assemble: false, //是否是拼团

    tabIndex: 0, //tab切换
    grade: 0, //好评率
    in_store: true, // 配送地区是否有货状态 默认有货
    cartGoodsCount: 0, //购物车商品数量
    /** 规格相关 */
    showSpecsPopup: false, // 是否显示规格选择弹窗 默认不显示 为false
    selectedSku: '', // 已选sku
    skuId: '', // 路由加载参数中携带的skuId
    pintuanId: '', // 路由加载参数中携带的pintuanId
    from_nav: '', //路由加载参数中携带的from_nav
    buyNum: 1, // 所选商品数量

    hiddenPrice: false, //是否隐藏价格
    canView: false, // 当前商品是否可预览

    /* 收藏相关 */
    collected: false, // 商品是否已被收藏

    scrollHeight: 0, // 滚动高度
    scrollTop: 0, // 滚动距离
    showGoTop: false, // 显示返回顶部按钮
    finished: false, // 是否加载完毕
    showShare: false, //分享
    isShowQRCode: false, //是否显示二维码弹窗
    mktprice: 0, //市场价
    rebate: 0, //分润返利
    jdGoodsDetail: '', //京东商品详情
    recommendGoodsList: [], //
    query: '',
    is_VIP: 1,
    //商家详情
    shops: "",
    params:{
      page_no:1,
      page_size:10
    },
    finished:false,
    recommend:[],
    flag:true,
    showAgreement:false,
    qrCode:false

  },
  // tab切换
  tabs(e) {
    let index = parseInt(e.currentTarget.dataset.index)
    this.setData({
      tabIndex: index
    })
  },
  async onLoad(options) {
    console.log('options');
    
    console.log(options)
             // 上下级关系获取绑定
  if(options.su){
    API_Distribution.accessShortLink({ su: options.su }).then(res => {
      wx.setStorageSync('inviteCode',res.mobile)
    })
  }
    // 页面初始化 options为页面跳转所带来的参数
    this.setData({
      goods_id: parseInt(options.goods_id) || '',
      skuId: options.sku_id || '',
      pintuanId: options.pintuan_id,
      from_nav: options.from_nav || ''
    })    
    if(options.scene){
      this.setData({qrCode:true})
      let scene=decodeURIComponent(options.scene)
      let arr = scene.split('&');
      let goodsId = arr[0].split('=')[1];
      let qrId = arr[1].split('=')[1];
      this.setData({goods_id:goodsId})
      wx.setStorageSync('qrId', qrId)
    }      
    wx.getSystemInfo({
      success: (res) => {
        this.setData({
          scrollHeight: res.windowHeight + 'px'
        })
      }
    })
    console.log('商品页拿到的su', options.su)
    options.su && API_Distribution.accessShortLink({
      su: options.su
    });
    if (wx.getStorageSync("access_token")){
    let response = await API_Distribution.generateShortLink();
    let query = response.message.substring(
      response.message.indexOf("?"),
      response.message.length
    );
    // console.log('商品页生成su', query)
    this.setData({
      query
    })
  } 
  },
  async onShow() {
    let goods = {}
	if (!this.data.isPreview) {
		try {
		  goods = await API_Goods.getGoods(this.data.goods_id)
		} catch (e) {
		  wx.showToast({
			title: '商品已不存在',
			icon: 'none'
		  })
		}
		goods.price = Foundation.formatPrice(goods.price)
		this.setData({
		  goods: goods,
		  grade: goods.grade,
		  param_list: goods.param_list,
		  gallery_list: goods.gallery_list || [],
		  canView: goods.is_auth !== 0 && goods.goods_off === 1,
		  selectedSku: ''
		})
		this.getGoodsInfo()
		if (goods.goods_source == 1) {
		  this.getJdGoodsImage(goods.sn)
		  this.getJdGoodsDetail(goods.sn)
		  // this.checkJdGoods(goods.sn)
		} else {
		  WxParse.wxParse('goodsDetail', 'html', goods.intro, this, 10)
		}
	}else{
		console.log('否')
  }
  //获取商家详情
  let data =await API_Shop.getShopBaseInfo(this.data.goods.seller_id);
  this.setData({shops:data});
  this.getRecommendGoodsList();
  },
  isPreviewImage:function(e){
	this.setData({
	  isPreview: e.detail.isPreview
	})
  },
  //获取京东商品商品图
  async getJdGoodsImage(sn) {
    let {
      token
    } = await API_Trade.getJDToken();
    wx.request({
      url: 'https://jdapi.oupinguoji.cn/jdapi/goods/image',
      method: 'get',
      header: {
        Authorization: 'Bearer ' + token
      },
      data: {
        sku: sn,
      },
      success: res => {
        // console.log(res)
        let list = res.data[sn].map(item => {
          return {
            original: 'http://img13.360buyimg.com/n0/' + item.path
          }
        })
        this.setData({
          gallery_list: list
        })
      }
    })
  },
  async getJdGoodsDetail(sn) {
    let {
      token
    } = await API_Trade.getJDToken();
    wx.request({
      url: 'https://jdapi.oupinguoji.cn/jdapi/goods',
      method: 'get',
      header: {
        Authorization: 'Bearer ' + token
      },
      data: {
        sku: sn,
        isShow: true
      },
      success: res => {
        wx.request({
          url: 'https://jdapi.oupinguoji.cn/jdapi/goods/style',
          method: 'get',
          header: {
            Authorization: 'Bearer ' + token
          },
          data: {
            sku: sn,
            type: 0
          },
          success: styleRes => {
            let {
              appintroduce
            } = res.data
            let {
              cssContent
            } = styleRes.data
            // //判断是否存在https图片连接，不存在就有的图片的话就替换
            // if (appintroduce.indexOf('https://img') == -1 && appintroduce.indexOf('http://img') == -1) {
            //   var reg = new RegExp(/\/\/img/, "gm")
            //   appintroduce = appintroduce.replace(reg, "https://img");
            // }
            // //判断是否有link的css样式，有就进行替换
            // if (appintroduce.indexOf(`<link rel='stylesheet' type='text/css' href='//`) != -1) {
            //   appintroduce = appintroduce.replace(/<link rel='stylesheet' type='text\/css' href='\/\//g, "<link rel='stylesheet' type='text/css' href='https://");
            // }
			
			// 配置图片大小 S
			
			appintroduce = appintroduce.replace(/(style="(.*?)")|(width="(.*?)")|(height="(.*?)")/ig, '')
			appintroduce = appintroduce.replace(/<img /gi, '<img width:100%; height:auto; ')
			
			
			// 配置图片大小 
            let html = `
        
      

            ${cssContent===undefined?"":cssContent}
            ${appintroduce===undefined?"":appintroduce}


            `

            // ${cssContent}
            // ${cssContent}
            // console.log(html)
            // console.log(cssContent)
            // console.log(appintroduce)
            this.setData({
              jdGoodsDetail: html
            })
            //             this.setData({
            //               jdGoodsDetail:`<style>.M15573762990441{width:100.00%; background-size:100% 100%; background-image:url(https://img30.360buyimg.com/sku/jfs/t1/39386/13/6654/308078/5cd3ad74Ed1a7e490/25fe500d97526a39.jpg); height:1328px}
            // </style>
            //   <div class="ssd-module-mobile-wrap" >
            //   <div class="ssd-module M15573762990441" data-id="M15573762990441">
            // </div>
            // </div>
            // `})
            // WxParse.wxParse('jdGoodsDetail', 'html', html, this)
            WxParse.wxParse('jdGoodsParams', 'html', res.data.param, this)
          }
        })
      }
    })
  },
  async getJdGoodsCheck(sn) {
    let {
      token
    } = await API_Trade.getJDToken();
    wx.request({
      url: 'https://jdapi.oupinguoji.cn/jdapi/goods/check',
      method: 'get',
      header: {
        Authorization: 'Bearer ' + token
      },
      data: {
        skuIds: sn,
      },
      success: res => {

      }
    })
  },
  //获取为你推荐商品
  getRecommendGoodsList() {
    API_Goods.getRecommendation(this.data.params).then(response=>{
      let { data } = response
      if(data && data.length){
        // data.forEach(key=>{
        //   key.refund_price = Foundation.formatPrice(key.refund_price)
        // })
        this.setData({ recommend: this.data.recommend.concat(data) })
      }else{
        this.setData({finished:true})
      }
    })
  },
  loadMore: function () {
    // console.log(this.data.finshed)
    if (!this.data.finshed) {
      this.setData({ "params.page_no": this.data.params.page_no + 1 })
      this.getRecommendGoodsList()
    } else {
      return
    }
  },
  onUrl(e){
    let path = e.currentTarget.dataset.path;
    wx.navigateTo({
      url: "/pages/goods/goods?goods_id="+path
    })
  },
  // 获取商品活动信息
  getGoodsInfo() {
    //如果商品可以查看
    if (this.data.canView) {
      let pages = getCurrentPages(); //获取加载页面
      let currentPage = pages[pages.length - 1]; //获取当前页面的对象
      let route = currentPage.route; //获取当前页面路径
      let goods_id = currentPage.options.goods_id; //获取当前路由参数
      let url = route + '/' + goods_id //完整路径
      API_Common.recordView(url) //记录浏览量统计
      if(this.data.qrCode){
        API_Goods.getGoodsSkus(this.data.goods_id).then(res => {
          console.log(res[0].mktprice)
          this.setData({
            mktprice: res[0].mktprice
          })
        })
        if (!wx.getStorageSync('refresh_token')) { // 如果没有登录
          console.log('未登录')
          API_Goods.getGoodsFenrun({
            goodsId: this.data.goods_id
          }).then(res => {
            console.log('未登录',res)
            this.setData({
              rebate: res.rebate
            })
            this.setData({
              is_VIP: res.is_vip
            })
          })
          } else {
          console.log('已登录')
          API_Goods.getGoodsFenrunS({
            goodsId: this.data.goods_id
          }).then(res => {
            console.log('未登录',res)
            this.setData({
              rebate: res.rebate
            })
            this.setData({
              is_VIP: res.is_vip
            })
          })
          }        
      }
      else{
      API_Goods.getGoodsSkus(goods_id).then(res => {
        console.log(res[0].mktprice)
        this.setData({
          mktprice: res[0].mktprice
        })
      })
	  if (!wx.getStorageSync('refresh_token')) { // 如果没有登录
		console.log('未登录')
		API_Goods.getGoodsFenrun({
		  goodsId: goods_id
		}).then(res => {
			console.log('未登录',res)
		  this.setData({
		    rebate: res.rebate
		  })
		  this.setData({
		    is_VIP: res.is_vip
		  })
		})
	  } else {
		console.log('已登录')
		API_Goods.getGoodsFenrunS({
		  goodsId: goods_id
		}).then(res => {
			console.log('未登录',res)
		  this.setData({
		    rebate: res.rebate
		  })
		  this.setData({
		    is_VIP: res.is_vip
		  })
		})
    }
  } 

      //如果存在sku_id 并且带有拼团标识
      if (this.data.skuId && this.data.from_nav === 'assemble') {
        this.setData({
          is_assemble: true
        })
        API_Promotions.getAssembleDetail(this.data.skuId).then(response => {
          response.reduce_moeny = Foundation.formatPrice(response.origin_price - response.sales_price)
          response.sales_price = Foundation.formatPrice(response.sales_price)
          response.origin_price = Foundation.formatPrice(response.origin_price)
          this.setData({
            assemble: response
          })
        })
      } else {
        //获取商品活动内容
        API_Promotions.getGoodsPromotions(this.data.goods_id).then(response => {
          const promotions = response
          let nowtime = parseInt(new Date() / 1000)
          if (promotions && promotions.length) {
            let prom = promotions[0].exchange || ''
            let groupbuy = promotions[0].groupbuy_goods_vo || ''
            let seckill = promotions[0].seckill_goods_vo || ''
            //格式化价格
            if (prom) {
              prom.exchange_money = Foundation.formatPrice(prom.exchange_money)
              prom.goods_price = Foundation.formatPrice(prom.goods_price)
            } else if (groupbuy) {
              groupbuy.price = Foundation.formatPrice(groupbuy.price)
              groupbuy.original_price = Foundation.formatPrice(groupbuy.original_price)
              groupbuy.end_time = promotions[0].end_time - nowtime
            } else if (seckill) {
              seckill.seckill_price = Foundation.formatPrice(seckill.seckill_price)
              seckill.original_price = Foundation.formatPrice(seckill.original_price)
            }
            this.setData({
              promotions: promotions,
              prom: prom,
              groupbuy: groupbuy,
              seckill: seckill
            })
          }
          if (!promotions || !promotions.length) {
            this.setData({
              hiddenPrice: false
            })
          }
          // 如果有团购，隐藏价格
          if (promotions.filter(item => item.groupbuy_goods_vo)[0]) {
            this.setData({
              hiddenPrice: true
            })
          }
          // 如果有限时抢购，隐藏价格
          if (promotions.filter(item => item.seckill_goods_vo)[0]) {
            this.setData({
              hiddenPrice: true
            })
          }
          // 如果有积分兑换，隐藏价格
          if (promotions.filter(item => item.exchange)[0]) {
            this.setData({
              hiddenPrice: true
            })
          }
        })
      }
    }
    if (wx.getStorageSync('refresh_token')) {
      //获取收藏状态
      API_Members.getGoodsIsCollect(this.data.goods_id).then(response => {
        this.setData({
          collected: response.message
        })
      })
      //获取购物车数量
      this.getAllCount()
    }
  },
  //获取购物车数量
  async getAllCount() {
    let _allCount = 0
    // const _shopList = wx.getStorageSync('shoplist')
    const {
      cart_list
    } = await API_Trade.getCarts()
    cart_list.forEach(shop => {
      shop.sku_list.forEach(item => {
        if (item.invalid !== 1) {
          _allCount += item.num
        }
      })
    })
    this.setData({
      cartGoodsCount: _allCount
    })
  },
  //配送地区是否有货发生改变
  handleInStockChange(e) {
    const in_store = e.detail
    this.setData({
      in_store: in_store
    })
  },

  // 所选规格发生变化 sku变化
  onSkuChanged(sku) {
    if (this.data.sku_id && this.data.from_nav === 'assemble') {
      this.setData({
        is_assemble: true
      })
      /** 查询获取某个拼团的sku详情 */
      const {
        sku_id
      } = sku.detail
      API_Promotions.getAssembleDetail(sku_id).then(res => {
        this.setData({
          assemble: res
        })
      })
    }
    if (sku.detail) {
      sku.detail.price = Foundation.formatPrice(sku.detail.price)
	  // console.log(sku.detail)
      this.setData({
        selectedSku: sku.detail
      })
    }
  },

  // 所选规格数量发生变化
  onNumChanged(num) {
    this.setData({
      buyNum: num.detail
    })
  },
  login(){
    if(!wx.getStorageSync('user')){
      this.setData({flag:false})
    }

    // this.getUserInfo()

    // if(wx.getStorageSync('user')){
    //   getApp().autoLogin()
    //   return
    // }else{
    //   wx.navigateTo({ url: '/pages/auth/login/login' })
    // }
  },
  closeMask(){
    this.setData({flag:true})
  },
  wxLoginAuth(){
    // this.getUserInfo()
    // wx.navigateTo({
    //   url: '/pages/auth/register/register',
    // })
    this.setData({flag:true})
    wx.getSetting({
      success(res) {
        if (res.authSetting['scope.userInfo']) {
          wx.setStorageSync('wxauth', true)
          setTimeout(() => {
            wx.navigateTo({
              url: '/pages/auth/register/register',
          })
            // if (wx.getStorageSync('refresh_token')) {
            //   // wx.switchTab({
            //   //   url: '/pages/mine/mine'
            //   // })
            //   //   wx.navigateTo({
            //   //     url: '/pages/auth/register/register',
            //   // })
            // } else {
            //   app.autoLogin()
            //   wx.switchTab({
            //     url: '/pages/home/home',
            //   })
            // }
          }, 1000)
        }
      }
    })    
  },
  showagreement(){
    this.setData({showAgreement:true})
  },

    //同意协议
  handleAgreement(e) {
      const agreed = JSON.parse(e.currentTarget.dataset.agreed)
      if (!agreed) {
        wx.switchTab({ url: '/pages/home/home'})
        this.setData({showAgreement:false,flag:true})
        console.log(agreed)
      } else {
        this.setData({
          showAgreement: false,
          agreed: agreed
        })
      }
  },
  // 去首页
  goHome() {
    wx.switchTab({
      url: '/pages/home/home'
    })
  },
  // 返回上页
  goReturn() {
    wx.navigateBack()
  },
  scroll(e) {
    if (e.detail.scrollTop > 200) {
      this.setData({
        showGoTop: true
      })
    } else {
      this.setData({
        showGoTop: false
      })
    }
  },
  goTop() {
    this.setData({
      scrollTop: 0
    })
  },
  // 跳转到购物车
  openCartPage() {
    wx.navigateTo({
      url: '/pages/cart/cart'
    })
  },
  // 跳转到店铺
  openSeller(e) {
    let seller_id = e.currentTarget.dataset.seller_id
    if(seller_id == 15){
      wx.switchTab({
        url: '/pages/home/home',
      })
    }else{
      wx.navigateTo({
        url: '/pages/shop/shop_id/shop_id?id=' + seller_id
      })
    }
    
  },
  // 收藏商品
  addCannelCollect() {
    if (!wx.getStorageSync('refresh_token')) {
      // wx.showToast({
      //   title: '您还未登录!',
      //   image: '../../static/images/icon_error.png'
      // })
      // return false
      this.setData({flag:false})
    }
    else{    const {
      goods_id
    } = this.data.goods
    if (this.data.collected) {
      API_Members.deleteGoodsCollection(goods_id).then(() => {
        wx.showToast({
          title: '取消收藏成功!'
        })
        this.setData({
          collected: false
        })
      })
    } else {
      API_Members.collectionGoods(goods_id).then(() => {
        wx.showToast({
          title: '收藏成功!'
        })
        this.setData({
          collected: true
        })
      })
    }}

  },
  //分享
  handShare() {
    if(!wx.getStorageSync('user')){
      this.setData({flag:false})
    }
    else{    this.setData({
      showShare: true
    })}

  },
  cloneDialog() {
    this.setData({
      showShare: false
    })
  },
  /** 加入购物车 */
  handleAddToCart: util.throttle(function () {
    if(!wx.getStorageSync('user')){
      this.setData({flag:false})
    }
    else{   if (!this.data.in_store || !this.isLogin()) return
    const {
      buyNum
    } = this.data
    const {
      sku_id
    } = this.data.selectedSku
    API_Trade.addToCart(sku_id, buyNum, this.getActivityId()).then(response => {
      //更新购物车数量
      this.getAllCount()
      wx.showModal({
        title: '提示',
        content: '加入购物车成功，要去看看么？',
        confirmColor: '#f42424',
        success: function (res) {
          if (res.confirm) {
            wx.navigateTo({
              url: '/pages/cart/cart'
            })
          }
        }
      })
    })}
 
  }),
  // 登录校验
  isLogin() {
    if (!this.data.selectedSku) {
      wx.showToast({
        title: '请选择商品规格！',
        icon: 'none',
        duration: 1500
      })
      this.setData({
        showSpecsPopup: true
      })
      return false
    }
    if (!wx.getStorageSync('refresh_token')) { // 如果没有登录
      // wx.showModal({
      //   title: '提示',
      //   content: '您还未登录，要现在去登录吗？',
      //   success(res) {
      //     if (res.confirm) {
      //       wx.navigateTo({
      //         url: '/pages/auth/register/register'
      //       })
      //     }
      //   }
      // })
      this.setData({flag:false})
      // return false
    } else {
      return true
    }
  },
  // 立即购买弹框
  BuyNow1(){
    if(!wx.getStorageSync('user')){
      this.setData({flag:false})
    }
    else{   this.setData({
      showSpecsPopup: true
    })}
 
  },
  //立即购买跳转
  BuyNow: util.throttle(function () {
    if (!this.data.in_store || !this.isLogin()) return
    const {
      buyNum
    } = this.data
    const {
      sku_id
    } = this.data.selectedSku
    API_Trade.buyNow(sku_id, buyNum, this.getActivityId()).then((response) => {
      console.log('response',response);
      
      this.setData({
        showSpecsPopup: false
      })
      wx.navigateTo({
        url: '/pages/shopping/checkout/checkout?way=BUY_NOW'
      })
    })
  }),
  //拼团买 创建拼团订单
  handleAssembleBuyNow: util.throttle(function () {
    if (!this.data.in_store || !this.isLogin()) return
    const {
      buyNum
    } = this.data
    const {
      sku_id
    } = this.data.selectedSku
    API_Trade.addToAssembleCart(sku_id, buyNum).then((response) => {
      wx.navigateTo({
        url: '/pages/shopping/checkout/checkout?from_nav=assemble'
      })
    })
  }),
  //参与拼团
  toAssembleBuyNow(e) {
    const order = e.detail
    if (!this.data.in_store || !this.isLogin()) return
    const {
      buyNum
    } = this.data
    const {
      sku_id
    } = this.data.selectedSku
    API_Trade.addToAssembleCart(sku_id, buyNum).then(response => {
      wx.navigateTo({
        url: `/pages/shopping/checkout/checkout?order_id=${order.order_id}&from_nav=assemble`
      })
    })
  },
  // 获取活动id
  getActivityId() {
    const {
      promotions
    } = this.data
    if (!promotions || !promotions.length) return ''
    let pro
    for (let i = 0; i < promotions.length; i++) {
      let item = promotions[i]
      if (item.exchange || item.groupbuy_goods_do || item.seckill_goods_vo) {
        pro = item
        break
      }
    }
    if (!pro) return ''
    return pro.activity_id
  },
  /** 分享 */
  onShareAppMessage: function () {
    return {
      title: this.data.goods.goods_name,
      desc: this.data.goods.goods_name,
      // path: '/pages/auth/register/register' + this.data.query  + '&goods_id=' + this.data.goods_id ,
      url:'https://h5.oupinguoji.cn/goods/'+this.data.goods_id,
      imageUrl: this.data.goods.thumbnail
    }
  },
  handleCreatePoster() {
    if (wx.getStorageSync("access_token")){
    this.setData({
      isShowQRCode: true
    })
    let _query = ""
    API_Distribution.generateShortLink({
      goods_id: this.data.goods_id
    }).then(response => {
      _query = response.message.substring(response.message.indexOf("?"), response.message.length)
      this.setData({
        _query: _query
      })
      new QRCode('myQrcode', {
        text: 'https://h5.oupinguoji.cn/goods/' + this.data.goods_id + _query,
        width: 170,
        height: 170,
        padding: 12, // 生成二维码四周自动留边宽度，不传入默认为0
        correctLevel: QRCode.CorrectLevel.L, // 二维码可辨识度
        callback: (res) => {
          // console.log(res)
          // 接下来就可以直接调用微信小程序的api保存到本地或者将这张二维码直接画在海报上面去，看各自需求
        }
      })
    })
  }
  },
  clonePoster() {
    this.setData({
      isShowQRCode: false
    })
  },
  tobeVIP:util.throttle(function ()  {
	  let that = this
	  // console.log(this.data.goods)
	  let itemList = this.data.goods.self_operated === 1 ? ['会员'] : ['荣耀', '会员']
	  wx.showActionSheet({  
		  itemList: itemList,  
		  success: function(res) {
			  if (res.tapIndex === 0) {
				console.log('会员')
				if (!that.isLogin()) {
					wx.navigateTo({ url: '/pages/auth/login/login' })
				} else {
					wx.navigateTo({
					  url: "/ucenter/open-vip/open-vip"
					})
				}
			  } else if (res.tapIndex === 1) {
				console.log('荣耀')
				if (!wx.getStorageSync('refresh_token')) {
				  wx.showModal({
				    title: '提示',
				    content: '您还未登录，要现在去登录吗？',
				    success(res) {
				      if (res.confirm) {
				        wx.navigateTo({
				          url: '/pages/auth/login/login'
				        })
				      }
				    }
				  })
				} else {
				  wx.navigateTo({
				    url: '/pages/shop/apply_member/apply_member?shop_id=' + that.data.goods.seller_id
				  })
				}
			  }
		  },  
		  fail: function(res) {  
			  console.log('取消')  
		  }  
	  })  
  })
})